package com.itheima.mapper;


import com.itheima.pojo.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from user where username=#{username}")
    User findByUserName(String username);

    /**
     * 添加
     * @param username
     * @param password 加密后的密码
     */
    @Insert("insert into user(username,password,create_time,update_time)" +
            " values(#{username},#{password},now(),now())")
    void add(@Param("username")String username,@Param("password") String password);


    /**
     * 修改用户信息
     * @param user
     */
    @Update("update user set nickname=#{nickname},email=#{email},update_time=#{updateTime} where id=#{id}")
    void update(User user);

    //添加头像
    @Update("update user set user_pic=#{user_pic},update_time=now() where id=#{id}")
    void updateAvatar(@Param("user_pic") String avatarUrl,@Param("id") Integer id );

    //修改密码
    @Update("update  user set password=#{password},update_time=now() where id=#{id}")
    void updatePwd(@Param("password") String newPwd,@Param("id") Integer id);
}
